package com.sicong.gateway.controller;

import com.sicong.gateway.config.Swagger2ResourceProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Primary;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger.web.*;

import java.util.List;

/**
 * swagger聚合接口
 *
 * @author chenww
 * @date 2020-11-25
 */
@RestController
@RequestMapping("/swagger-resources")
@ConditionalOnBean(Swagger2ResourceProvider.class)
public class Swagger2ResourceController {

    private final Swagger2ResourceProvider swagger2ResourceProvider;

    @Autowired
    public Swagger2ResourceController(Swagger2ResourceProvider swagger2ResourceProvider) {
        this.swagger2ResourceProvider = swagger2ResourceProvider;
    }

    @GetMapping("/configuration/security")
    public ResponseEntity<SecurityConfiguration> securityConfiguration() {
        return new ResponseEntity<>(SecurityConfigurationBuilder.builder().build(), HttpStatus.OK);
    }

    @GetMapping("/configuration/ui")
    public ResponseEntity<UiConfiguration> uiConfiguration() {
        return new ResponseEntity<>(UiConfigurationBuilder.builder().build(), HttpStatus.OK);
    }

    @GetMapping
    public ResponseEntity<List<SwaggerResource>> swaggerResources() {
        return new ResponseEntity<>(swagger2ResourceProvider.get(), HttpStatus.OK);
    }

}
